from typing import Optional

from sqlalchemy import BigInteger, DateTime, Integer, PrimaryKeyConstraint, String, func
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
import datetime

from config.database import Base
from utils.uuid import UUID


class CmsDriver(Base):
    __tablename__ = 'cms_driver'
    __table_args__ = (
        PrimaryKeyConstraint('id', name='_copy_15'),
        {'comment': '驾驶员信息'}
    )

    id: Mapped[int] = mapped_column(BigInteger, primary_key=True, default=int(UUID().uuid()))
    driver_id: Mapped[str] = mapped_column(String(32), comment='驾驶员编码')
    driver_name: Mapped[str] = mapped_column(String(32), comment='驾驶员姓名')
    driver_model: Mapped[str] = mapped_column(String(32), comment='准驾车型')
    phone: Mapped[str] = mapped_column(String(32), comment='手机号')
    identity_card: Mapped[str] = mapped_column(String(64), comment='身份证号')
    state: Mapped[int] = mapped_column(Integer, comment='状态（0 失效，1 有效）')
    create_time: Mapped[datetime.datetime] = mapped_column(DateTime, comment='创建时间', server_default=func.now())
    experation_begin: Mapped[Optional[datetime.datetime]] = mapped_column(DateTime, comment='驾照有效期开始时间')
    experation_end: Mapped[Optional[datetime.datetime]] = mapped_column(DateTime, comment='驾照有效期结束时间')
    certificate_no: Mapped[Optional[str]] = mapped_column(String(255), comment='从业资格证号')
    certificate_image: Mapped[Optional[str]] = mapped_column(String(255), comment='从业资格证图片')
    create_by: Mapped[Optional[str]] = mapped_column(String(32), comment='创建人')
    update_time: Mapped[Optional[datetime.datetime]] = mapped_column(DateTime, comment='修改时间',
                                                                     server_default=func.now(), onupdate=func.now())
    update_by: Mapped[Optional[str]] = mapped_column(String(32), comment='修改人')
    car_team_id: Mapped[Optional[str]] = mapped_column(String(32), comment='所属车队id')
    account: Mapped[Optional[str]] = mapped_column(String(32), comment='登陆账号')
    password: Mapped[Optional[str]] = mapped_column(String(32), comment='密码')
